import React, { Component } from 'react';
import connect from '../../../redux-component/connect'
import Informations from './InformationsViews'
import Line from './informationLine'

@connect
class Information extends Component {
    state = { 
      title:'个人资料',
      informationsList:{},
      imgInput:''    
     }
     async componentDidMount(){
         let a =await fetch('/Legang/user/myface',{
             method:'post',
             body:{
                 uid:this.props.uid,
             },
             headers:{'Content-Type': 'application/x-www-form-urlencoded'}
         }).then(response=>response.json()).then(res=>res)
        //  console.log(a,11111)
         this.setState({
             informationsList:a
         })
     }
    render() { 
        return ( 
            <>
                <Informations back={()=>this.goBack()} title={this.state.title}></Informations>
                <Line props={this.props} imgInput={this.state.imgInput} changeItem={(e)=>{this.getem(e)}} list={this.state.informationsList} uid={this.props.uid}></Line>
            </>
         );
    }
    goBack(){
        this.props.history.go(-1)
    }
    getem(e) {
        let $target = e.target || e.srcElement
        let file = $target.files[0]
        let headerImg='aaa'
        var reader = new FileReader()
        reader.onload =async function(data) {
          let res = data.target || data.srcElement
          headerImg=  res.result
        }
        let formdata = new FormData()
        formdata.append('uid',this.props.uid)
        formdata.append('headimg',file)
        reader.readAsDataURL(file)
        setTimeout(() => {
            this.setState({
                imgInput:headerImg
            })
        }, 1000);

        // fetch('/Legang/user/updateuser',{   
        //     method:"POST",
        //     // headers:{
        //     //     "Content-type":"application/x-www-form-urlencoded",
        //     // },     
        //     body: formdata
        //   })    
        //   .then(response => response.json())
        //   .then(result => {
        //     console.log(result)
            
        //     // if(result.flag){
        //     //   console.log(result.data)
        //     //   userData.uid = result.data.uid
        //     //   userData.himg = result.data.himg
        //     //   userData.exp = result.data.exp
        //     //   userData.username = result.data.username
      
        //     //   // replace替换当前路由，路由表中不存在本页路由
        //     //   // this.props.history.replace('/index/home')
        //     //   this.props.history.push('/index/home')
        //     // }else{
        //     //   Toast.info(result.errorMsg,1.5)
        //     // }
        //   })
      }
}
 
export default Information;